package com.atguigu1.core.acc

/**
 *
 * @description: 传名参数和传值参数的区别
 * @time: 2021-03-17 22:52
 * @author: baojinlong 
 **/
object Spark04MyParamDemo {
  // 传值参数 这是函数入参
  def test1(code: () => Unit): Unit = {
    println("start")
    code()
    println("end")
  }

  /**
   * 传名参数
   *
   * @param code
   */
  def test(code: => Unit): Unit = {
    println("start")
    code
    println("end")
  }

  def test2(code: => Int): Unit = {
    println("start")
    println("code= " + code)
    println("end")
  }

  def main(args: Array[String]): Unit = {
    test1 {
      println("1111")
      () => {
        println("2222")
      }
    }
    println("*******************")

    test {
      println("1111")
      println("2222")
    }

    println("***********")
    test2 {
      println("1111")
      println("2222")
      2
    }
  }

}
